home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / ext / events / clock.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  5KB  |  154 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import time
  5. from gi.repository import Gtk, GLib
  6. from quodlibet import app
  7. from quodlibet import config
  8. from quodlibet.plugins.events import EventPlugin
  9. from quodlibet.qltk.entry import ValidatingEntry
  10. from quodlibet.util import connect_obj
  11.  
  12. class Alarm(EventPlugin):
  13.     PLUGIN_ID = 'Alarm Clock'
  14.     PLUGIN_NAME = _('Alarm Clock')
  15.     PLUGIN_DESC = _('Wake you up with loud music.')
  16.     PLUGIN_ICON = Gtk.STOCK_DIALOG_INFO
  17.     PLUGIN_VERSION = '0.22'
  18.     _pref_name = 'alarm_times'
  19.     _times = [
  20.         'HH:MM'] * 7
  21.     _enabled = False
  22.     
  23.     def __init__(self):
  24.         
  25.         try:
  26.             self._times = config.get('plugins', self._pref_name).split(' ')[:7]
  27.         except:
  28.             pass
  29.  
  30.         self._times = self._times + [
  31.             'HH:MM'] * 7[:7]
  32.         GLib.timeout_add(30000, self._check)
  33.  
  34.     
  35.     def enabled(self):
  36.         self._enabled = True
  37.  
  38.     
  39.     def disabled(self):
  40.         self._enabled = False
  41.  
  42.     
  43.     def is_valid_time(time):
  44.         
  45.         try:
  46.             (hour, minute) = map(int, time.split(':'))
  47.         except:
  48.             return False
  49.  
  50.         if hour < 24:
  51.             pass
  52.         return minute < 60
  53.  
  54.     is_valid_time = staticmethod(is_valid_time)
  55.     
  56.     def plugin_on_song_started(self, song):
  57.         pass
  58.  
  59.     
  60.     def _entry_changed(self, entries):
  61.         self._times = map(ValidatingEntry.get_text, entries)
  62.         config.set('plugins', self._pref_name, ' '.join(self._times))
  63.  
  64.     
  65.     def _ready(self):
  66.         tdata = time.localtime()
  67.         goal = self._times[tdata.tm_wday]
  68.         
  69.         try:
  70.             (ghour, gminute) = map(int, goal.split(':'))
  71.         except:
  72.             return False
  73.  
  74.         return (tdata.tm_hour, tdata.tm_min) == (ghour, gminute)
  75.  
  76.     
  77.     def _fire(self):
  78.         if self._enabled and app.player.paused:
  79.             if app.player.song is None:
  80.                 app.player.next()
  81.             else:
  82.                 app.player.paused = False
  83.         
  84.         GLib.timeout_add(60000, self._longer_check)
  85.  
  86.     
  87.     def _longer_check(self):
  88.         if self._ready():
  89.             self._fire()
  90.         else:
  91.             GLib.timeout_add(30000, self._check)
  92.  
  93.     
  94.     def _check(self):
  95.         if self._ready():
  96.             self._fire()
  97.         else:
  98.             return True
  99.  
  100.     
  101.     def PluginPreferences(self, parent):
  102.         t = Gtk.Table(n_rows = 2, n_columns = 7)
  103.         t.set_col_spacings(6)
  104.         entries = []
  105.         for i in range(7):
  106.             e = ValidatingEntry(Alarm.is_valid_time)
  107.             e.set_size_request(100, -1)
  108.             e.set_text(self._times[i])
  109.             e.set_max_length(5)
  110.             e.set_width_chars(6)
  111.             day = Gtk.Label(label = time.strftime('_%A:', (2000, 1, 1, 0, 0, 0, i, 1, 0)))
  112.             day.set_mnemonic_widget(e)
  113.             day.set_use_underline(True)
  114.             day.set_alignment(0, 0.5)
  115.             t.attach(day, 0, 1, i, i + 1, xoptions = Gtk.AttachOptions.FILL)
  116.             t.attach(e, 1, 2, i, i + 1, xoptions = Gtk.AttachOptions.FILL)
  117.             entries.append(e)
  118.         
  119.         for e in entries:
  120.             connect_obj(e, 'changed', self._entry_changed, entries)
  121.         
  122.         return t
  123.  
  124.  
  125.  
  126. class Lullaby(Alarm):
  127.     PLUGIN_ID = 'Lullaby'
  128.     PLUGIN_NAME = _('Lullaby')
  129.     PLUGIN_DESC = _('Fade out and pause your music.')
  130.     PLUGIN_ICON = Gtk.STOCK_MEDIA_PAUSE
  131.     PLUGIN_VERSION = '0.20'
  132.     _pref_name = 'lullaby_times'
  133.     
  134.     def _fire(self):
  135.         if self._enabled:
  136.             GLib.timeout_add(500, self._fade_out)
  137.             self._Lullaby__was_volume = app.player.volume
  138.         else:
  139.             GLib.timeout_add(30000, self._check)
  140.  
  141.     
  142.     def _fade_out(self):
  143.         app.player.volume -= 0.005
  144.         if app.player.volume == 0:
  145.             app.player.paused = True
  146.         if app.player.paused:
  147.             app.player.volume = self._Lullaby__was_volume
  148.             GLib.timeout_add(30000, self._check)
  149.         else:
  150.             return True
  151.         return app.player
  152.  
  153.  
  154.